﻿using System;

using IdeaNMR.Shared;
using IdeaNMR.Web.Core;

namespace IdeaNMR.Web
{
    public abstract class DesignHardObject_BasePage<T> : DesignBaseObject_BasePage<T>
        where T : HardObject, IHardObjectRelations, new()
    {
        protected HardObjectFacade<T> HardObjectInfo
        {
            get
            {
                return this.EntityFacade as HardObjectFacade<T>;
            }
            set
            {
                this.EntityFacade = value;
            }
        }

        #region Page Life Cycle
        
        #endregion

        protected override void InitiateObject()
        {
            this.HardObjectInfo = (this.TargetID.HasValue)
                        ? new HardObjectFacade<T>(this.TargetID.Value, ScrewTurnWikiFacade.Username)
                        : new HardObjectFacade<T>(ScrewTurnWikiFacade.Username);
        }

        protected override void SetValidationParameters()
        {
            base.SetValidationParameters();

            tbContactPerson.MaxLength = Sanitar.ContactPerson.MaxLength;
            rfvContactPerson.Text = revContactPerson.Text = Sanitar.ContactPerson.ErrorMsg;
            revContactPerson.ValidationExpression = Sanitar.ContactPerson.ValidationRegex;

            tbContactMail.MaxLength = Sanitar.ContactMail.MaxLength;
            rfvContactMail.Text = revContactMail.Text = Sanitar.ContactMail.ErrorMsg;
            revContactMail.ValidationExpression = Sanitar.ContactMail.ValidationRegex;

            tbLocation.MaxLength = Sanitar.Location.MaxLength;
            rfvLocation.Text = revLocation.Text = Sanitar.Location.ErrorMsg;
            revLocation.ValidationExpression = Sanitar.Location.ValidationRegex;
        }
        protected override void UpdateFormData()
        {
            base.UpdateFormData();

            var obj = this.HardObjectInfo.EntityObject;

            this.tbContactPerson.Text = obj.ContactPerson;
            this.tbContactMail.Text = obj.ContactEmail;
            this.tbLocation.Text = obj.Location;
        }
        protected override void CollectFormData()
        {
            base.CollectFormData();

            var obj = this.HardObjectInfo.EntityObject;

            obj.ContactPerson = this.tbContactPerson.Text;
            obj.ContactEmail = this.tbContactMail.Text;
            obj.Location = this.tbLocation.Text;
        }

        #region Page Controls Declaration
        protected global::System.Web.UI.WebControls.TextBox tbContactPerson;
        protected global::System.Web.UI.WebControls.RequiredFieldValidator rfvContactPerson;
        protected global::System.Web.UI.WebControls.RegularExpressionValidator revContactPerson;

        protected global::System.Web.UI.WebControls.TextBox tbContactMail;
        protected global::System.Web.UI.WebControls.RequiredFieldValidator rfvContactMail;
        protected global::System.Web.UI.WebControls.RegularExpressionValidator revContactMail;

        protected global::System.Web.UI.WebControls.TextBox tbLocation;
        protected global::System.Web.UI.WebControls.RequiredFieldValidator rfvLocation;
        protected global::System.Web.UI.WebControls.RegularExpressionValidator revLocation;
        #endregion
    }
}